home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / main / linuxconf.c < prev    next >
C/C++ Source or Header  |  1996-08-01  |  5KB  |  175 lines

  1. #include <unistd.h>
  2. #include "../askrunlevel/askrunlevel.h"
  3. #include "../misc/misc.h"
  4. #include "../xconf/xconf.h"
  5. #include "../netconf/netconf.h"
  6. #include "../userconf/userconf.h"
  7. #include "../fstab/fstab.h"
  8. #include "../main/main.h"
  9. #include "../paths.h"
  10. #include "main.m"
  11.  
  12. static HELP_FILE help_intro (HELP_MAIN,"intro");
  13. static HELP_FILE help_control (HELP_MAIN,"control");
  14. static HELP_FILE help_shutdown (HELP_MAIN,"shutdown");
  15.  
  16. /*
  17.     Interactive control of a shutdown or reboot
  18. */
  19. static void linuxconf_boot()
  20. {
  21.     DIALOG dia;
  22.     char oper=0;
  23.     dia.newf_radio ("",oper,0,MSG_U(F_REBOOT,"Reboot"));
  24.     dia.newf_radio ("",oper,1,MSG_U(F_HALT,"Shutdown & halt"));
  25.     int grace = 1;
  26.     dia.newf_num   (MSG_U(F_DELAI,"Delay before shutdown(minutes)"),grace);
  27.     SSTRING message;
  28.     dia.newf_str   (MSG_U(F_MESSAGE,"Message"),message);
  29.     if (dia.edit (MSG_U(T_SHUTDOWN,"Shutdown control panel")
  30.         ,MSG_U(I_SHUTDOWN,"You can force a reboot or a final shutdown\n"
  31.             "of this computer")
  32.         ,help_shutdown
  33.         ,0)==MENU_ACCEPT){
  34.         setuid (0);
  35.         chdir ("/");
  36.         char timestr[10];
  37.         sprintf (timestr,"+%d",grace);
  38.         execl ("/sbin/shutdown","/sbin/shutdown"
  39.             ,oper == 0 ? "-r" : "-h"
  40.             ,timestr,message.get(),NULL);    
  41.     }
  42. }
  43.  
  44. /*
  45.     control panel to activate different things, not to configure.
  46.     Return != 0 if the last task done was an "update" of the system state
  47. */
  48. static int linuxconf_control()
  49. {
  50.     int choice = 0;
  51.     int was_checked = 0;
  52.     while (1){
  53.         static const char *run_level  = MSG_U(M_RUNLEVEL,"init Run Level");
  54.         static const char *reboot = MSG_U(M_REBOOT,"Shutdown/Reboot");
  55.         static const char *update = MSG_U(M_UPDATE,"Activate configuration");
  56.  
  57.         static const char *menuopt[]={
  58.             " ",        update,
  59.             " ",        reboot,
  60.             //" ",        run_level,
  61.             NULL
  62.         };
  63.         MENU_STATUS code = xconf_menu (MSG_U(T_CONTROL,"Control panel")
  64.             ,MSG_U(I_CONTROL
  65.                 ,"This menu let you do things, not configure.")
  66.             ,help_control
  67.             ,menuopt,choice);
  68.         if (code != MENU_OK){
  69.             break;
  70.         }else if (perm_rootaccess (MSG_U(Q_SYSTASK,"to perform system task"))){
  71.             was_checked = 0;
  72.             const char *key = menuopt[choice*2+1];
  73.             if (key == update){
  74.                 int status = netconf_checkupdate();
  75.                 was_checked = status != -1;
  76.                 if (status == 0) xconf_notice (MSG_U(N_NOJOB,"Nothing to do!"));
  77.             }else if (!simul_isdemo()){
  78.                 if (key == reboot){
  79.                     linuxconf_boot();
  80.                 }else if (key == run_level){
  81.                 }
  82.             }else{
  83.                 xconf_error (MSG_U(E_DEMO,"Not in demo mode"));
  84.             }
  85.         }
  86.     }
  87.     return was_checked;
  88. }
  89.  
  90. /*
  91.     Main dispatcher to all other configs
  92. */
  93. void linuxconf_main(int dontcheck)
  94. {
  95.     int choice = 0;
  96.     int was_checked = 0;
  97.     while (1){
  98.         static const char *config_basic  = MSG_U(MNU_BASIC,"basic host information");
  99.         static const char *config_askrun = MSG_U(MNU_BOOT,"boot mode");
  100.         static const char *view_logs     = MSG_U(MNU_LOGS,"logs");
  101.         static const char *config_fstab     = MSG_U(MNU_FILESYS,"File systems");
  102.         static const char *config_graphic= MSG_U(MNU_GRAPH,"Graphic mode (X)");
  103.         static const char *config_net     = MSG_U(MNU_NET,"Networking");
  104.         static const char *config_user    = MSG_U(MNU_USERS,"Users accounts");
  105.         static const char *config_datetime = MSG_U(MNU_DATE,"date & time");
  106.         static const char *config_file    = MSG_U(MNU_CONFIGS,"all configuration files");
  107.         static const char *commands    = MSG_U(MNU_COMMANDS,"all commands and daemons");
  108.         static const char *control    = MSG_U(MNU_CONTROL,"Control panel");
  109.         static const char *config_module = MSG_U(MNU_MODULE,"Linuxconf's modules");
  110.  
  111.         static const char *menuopt[]={
  112.             MSG_U(MNU_CONFIG,"Configure"),config_basic,
  113.             " ",        config_net,
  114.             " ",        config_user,
  115.             " ",        config_fstab,
  116.             " ",        config_graphic,
  117.             " ",        config_askrun,
  118.             " ",        config_module,
  119.             MSG_U(MNU_SET,"Set"),        config_datetime,
  120.             "-",        "",
  121.             " ",        control,
  122.             MSG_U(MNU_VIEW,"View"),        view_logs,
  123.             MSG_U(MNU_LIST,"List"),        config_file,
  124.             " ",                        commands,
  125.             NULL
  126.         };
  127.         char title[80];
  128.         extern char *revision;
  129.         sprintf (title,"%s %s"
  130.             ,MSG_U(TITLE,"LINUX Configuration manager"),revision);
  131.         MENU_STATUS code = xconf_menu (title
  132.             ,MSG_U(MNU_INTRO,"This is the main entry to Linux configuration.\n"
  133.              "\n"
  134.              "Use the TAB key to nagigate between the field\n"
  135.              "section and the button bar at the bottom\n"
  136.              "Check out the help of this screen. It is an\n"
  137.              "introduction to Linuxconf")
  138.             ,help_intro
  139.             ,menuopt,choice);
  140.         if (code != MENU_OK){
  141.             break;
  142.         }else{
  143.             was_checked = 0;
  144.             const char *key = menuopt[choice*2+1];
  145.             if (key == config_basic){
  146.                 netconf_edithost();
  147.             }else if (key == config_fstab){
  148.                 fstab_edit ();
  149.             }else if (key == config_graphic){
  150.                 xconf_edit ();
  151.             }else if (key == config_net){
  152.                 netconf_edit ();
  153.             }else if (key == config_askrun){
  154.                 askrunlevel_config();
  155.             }else if (key == config_module){
  156.                 module_config();
  157.             }else if (key == view_logs){
  158.                 boot_showlog();
  159.             }else if (key == config_user){
  160.                 userconf_edit();
  161.             }else if (key == config_file){
  162.                 configf_show();
  163.             }else if (key == commands){
  164.                 daemon_config();
  165.             }else if (key == config_datetime){
  166.                 datetime_edit();
  167.             }else if (key == control){
  168.                 was_checked = linuxconf_control();
  169.             }
  170.         }
  171.     }
  172.     if (!dontcheck && !was_checked) netconf_checkupdate();
  173. }
  174.  
  175.